package com.mmy.fta.cargo.server.service;

import com.mmy.fta.cargo.server.dto.CargoBlackboardPageDTO;
import com.mmy.fta.cargo.server.dto.CargoBlackboardPageRequestDTO;
import com.mmy.fta.cargo.server.entity.CargoInfoEntity;
import com.mmy.fta.cargo.server.mapper.CargoInfoEntityMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author guohao.xie
 * @apiNote
 * @exportable
 * @since 2021/10/24
 */
@Service
@Slf4j
public class CargoBlackboardPageService {
    @Autowired
    CargoInfoEntityMapper cargoInfoEntityMapper;

    /**
     * 货主小黑板分页查询
     */
    public CargoBlackboardPageDTO getCargoPageInfo(CargoBlackboardPageRequestDTO cargoBlackboardPageRequestDTO) {
        List<CargoInfoEntity> result =
                cargoInfoEntityMapper.selectCargoPage(cargoBlackboardPageRequestDTO.getOpenId(),
                        cargoBlackboardPageRequestDTO.getPageNum() * cargoBlackboardPageRequestDTO.getPageSize());
        log.info("货主小黑板分页查询结果：{}",result);
        CargoBlackboardPageDTO cargoBlackboardPageDTO = new CargoBlackboardPageDTO();
        cargoBlackboardPageDTO.setList(result);
        return cargoBlackboardPageDTO;
    }

    public int getCargoPageTotalSize(String openId) {
        return cargoInfoEntityMapper.count(openId);
    }


    /**
     * 查询货主小黑板发货中
     */
    public CargoBlackboardPageDTO getHistoryCargoPageInfo(CargoBlackboardPageRequestDTO cargoBlackboardPageRequestDTO) {
        List<CargoInfoEntity> result =
                cargoInfoEntityMapper.selectHistoryCargoPage(cargoBlackboardPageRequestDTO.getOpenId(),
                        cargoBlackboardPageRequestDTO.getPageNum() * cargoBlackboardPageRequestDTO.getPageSize());
        log.info("查询货主小黑板'发货中'详情：{}",result);
        CargoBlackboardPageDTO cargoBlackboardPageDTO = new CargoBlackboardPageDTO();
        cargoBlackboardPageDTO.setList(result);
        return cargoBlackboardPageDTO;
    }

    /**
     * 查询货主小黑板'发货中'总条数
     */
    public int getHistoryCargoPageTotalSize(String shipperIdNo) {
        int num = cargoInfoEntityMapper.countHistory(shipperIdNo);
        log.info("查询货主小黑板'发货中'总条数：{}",num);
        return num;
    }

    /**
     * 货主编辑
     */
    public int editCargo(CargoInfoEntity cargoInfoEntity) {
        int num= cargoInfoEntityMapper.editCargo(cargoInfoEntity);
        log.info("货主编辑影响行数：{}",num);
        return num;
    }

    /**
     * 货主删除
     */
    public int deleteCargo(String cargoId) {
        int num=cargoInfoEntityMapper.deleteCargo(cargoId);
        log.info("货主删除影响行数：{}",num);
        return num;
    }

    public int upCargo(CargoInfoEntity cargoInfoEntity) {
        int num= cargoInfoEntityMapper.upCargo(cargoInfoEntity);
        log.info("货主编辑影响行数：{}",num);
        return num;
    }


//    /**
//     * 调用分页插件完成分页
//     */
//    private PageInfo<CargoInfoEntity> getPageInfo(CargoBlackboardPageRequestDTO pageRequest) {
//        int pageNum = pageRequest.getPageNum();
//        int pageSize = pageRequest.getPageSize();
//        PageHelper.startPage(pageNum, pageSize);
//        List<CargoInfoEntity> result = cargoInfoEntityMapper.selectCargoPage(pageRequest.getShipperIdNo());
//        return new PageInfo<CargoInfoEntity>(result);
//    }

}
